﻿using B.S.BasicData.Api.Read.Application.Command.Account;
using B.S.BasicData.Api.Read.Application.Command.GridPerson;
using B.S.BasicData.Api.Read.Dtos;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Read.Controllers
{
    /// <summary>
    /// 账号控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数:注入中介者
        /// </summary>
        /// <param name="mediator"></param>
        public AccountController(IMediator mediator )
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<int>> Login([FromQuery]LoginAccountCommand request) { 
            return mediator.Send(request);        
        }
        /// <summary>
        /// 查询账号列表的接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public Task<ApiResult<List<AccountDto>>> GetAccount([FromQuery]GetAccountCommand request) {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询网格人员分页列表
        /// </summary>
        /// <param name="request">请求命令</param>
        /// <returns>中介者的响应内容:网格人员分页列表</returns>
        [HttpGet]
        [Authorize]
        public Task<ApiPaging<AccountDto>> GetGridPersonPage([FromQuery]GetGridPersonCommand request) {
            return mediator.Send(request);
        }
    }
}
